<template>
  <div class="relations-container">
    <Search></Search>
    <UserList :userList="userList"></UserList>
    <UserRelationInfo></UserRelationInfo>
  </div>
</template>

<script>
  import { Search, UserList, UserRelationInfo } from './components'
  import { getUserRelation } from '../../api/api'

  export default {
    components: {
      Search,
      UserList,
      UserRelationInfo
    },
    data() {
      return {
        userList: []
      }
    },
    created() {
      const userInfo = this.$db.read().get('user').value()
      const userId = userInfo.userId
      if (userId) {
        this.getUserRelation(userId)
      }
    },
    methods: {
      getUserRelation(userId) {
        const params = { userId: userId }
        getUserRelation(params).then(response => {
          this.userList = response.data
        })
      }
    }
  }
</script>


